package com.tj.test.sys.controller;

import com.tj.test.sys.po.Answerpaper;
import com.tj.test.sys.service.impl.AnswerpaperService;
import com.tj.test.sys.tool.ResponseMessage;
import com.tj.test.sys.tool.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@CrossOrigin
@RequestMapping("/answerpaper")
@Api(tags = "answerpaper")
public class AnswerpaperController {
    @Autowired
    private AnswerpaperService service;

    @ApiOperation("查询所有试卷答题表信息")
    @RequestMapping(value = "/selectAllAnswerpaper",method = RequestMethod.GET)
    @ResponseBody
    public ResponseMessage selectAllAnswerpaper(){
        Map<String,List<Answerpaper>> map=new HashMap<>();
        List<Answerpaper> list=service.selectAllAnswerpaper();
        if (!list.isEmpty()){
            map.put("AllAnswerpaper",list);
            return Result.success("查询成功",map);
        }
        return Result.error("查询失败",false);
    }

    @ApiOperation("插入试卷答题表信息")
    @RequestMapping(value = "/insertAnswerpaper",method = RequestMethod.GET)
    @ResponseBody
    public ResponseMessage insertAnswerpaper(Answerpaper answerpaper){
        int temp=0;
        if (answerpaper!=null){
            if (answerpaper.getAnswerpaperid()!=0){
                temp=service.insertAnswerpaper(answerpaper);
                if (temp>0) {return Result.success("插入试卷答题表信息成功",temp);}
                else  {return Result.error("该试卷答题表已存在",temp);}
            }
        }
        return Result.error("插入试卷答题表信息失败",temp);
    }

    @ApiOperation("删除试卷答题表信息")
    @RequestMapping(value = "/deleteAnswerpaper",method = RequestMethod.GET)
    @ResponseBody
    public ResponseMessage deleteAnswerpaper(Answerpaper answerpaper){
        int temp=0;
        if (answerpaper!=null){
            if (answerpaper.getAnswerpaperid()!=0){
                temp=service.deleteAnswerpaper(answerpaper);
                if (temp>0) {return Result.success("删除试卷答题表信息成功",temp);}
                else {return Result.error("无该试卷答题表",temp);}
            }
        }
        return Result.error("删除试卷答题表信息失败",temp);
    }

    @ApiOperation("修改试卷答题表信息")
    @RequestMapping(value = "/updateAnswerpaper",method = RequestMethod.GET)
    @ResponseBody
    public ResponseMessage updateAnswerpaper(Answerpaper answerpaper){
        int temp=0;
        if (answerpaper!=null){
            if (answerpaper.getAnswerpaperid()!=0){
                temp=service.updateAnswerpaper(answerpaper);
                if (temp>0) {return Result.success("更新试卷答题表信息成功",temp);}
                else {return Result.error("无该试卷答题表信息",temp);}
            }
        }
        return Result.error("更新试卷答题表信息失败",temp);
    }
}
